fix: ensure idempotent project-relative path rewriting in CommandRegistrar - #4553
darion-yaphet wants to merge 1 commit into
Conversation
…strar
Replace the fragile pattern of three sequential string replacements followed by three re.sub calls and trailing `.replace(".specify/.specify/", ".specify/")` / `.replace(".specify.specify/", ".specify/")` patches in CommandRegistrar.rewrite_project_relative_paths.
Consolidate the transformation into a unified regex match callback that:
- Inspects matched path prefixes (`.specify/`, `../`, `./`, `/`, or bare)
- Naturally guards already-normalized `.specify/` paths from double-prefixing
- Directs parent relative references (`../`) to root `.specify/<target>/`
- Preserves extension-local script scoping when extension_id is provided
- Expands boundary delimiters to include Markdown brackets, parentheses, braces, angle brackets, and backticks
Add unit tests in tests/test_extensions.py covering repeated passes for idempotency, markdown enclosure delimiters, and edge-case inputs.
|
The delimiter and deeper-parent-path improvements have useful regression coverage. Before merge, please preserve parent-relative paths following Please also clarify the description: the supplied samples already remain stable under repeated rewriting on the old code; the demonstrated improvements are routing and delimiter handling. Finally, complete this PR’s AI disclosure with the tool, model, mode/settings, and extent of assistance—the checkbox alone does not describe the contribution. Drafted for @mnriem by GitHub Copilot (model: GPT-6 Astra; comment drafting). |
There was a problem hiding this comment.
🟢 Approval recommended
The refactor preserves routing behavior and includes focused regression coverage.
Pull request overview
Refactors project-relative path rewriting into an idempotent, single-pass implementation.
Changes:
- Consolidates path normalization into one regex callback.
- Adds regression coverage for idempotency, delimiters, and invalid inputs.
File summaries
| File | Description |
|---|---|
src/specify_cli/agents.py |
Implements unified path rewriting. |
tests/test_extensions.py |
Adds comprehensive regression tests. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced (auto)
Note
Copilot is running an experiment and ran this review at Balanced.
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Description
used
.replace(".specify/.specify/", ".specify/").replace(".specify.specify/", ".specify/")as an ad-hoc post-processing fix. This "patch-on-patch" design wasfragile, caused redundant string scanning, and risked regressions when paths were processed multiple times.
source and eliminating the need for subsequent
.replace()corrections.3. Deterministic routing: Parent-relative paths (
../) consistently route to root.specify/<target>/, while top-level / relativescripts/preserveextension-local scoping when
extension_idis supplied.4. Expanded delimiters: Recognizes common Markdown punctuation enclosures such as brackets
[], parentheses(), braces{}, angle brackets<>, quotes,and backticks.
Testing